/**
 * @description: 控制用户操作权限
 */
import type { Directive, DirectiveBinding, VNode } from 'vue';

const elBlur = (el: HTMLElement) => () => el?.blur();
export const blur: Directive = {
  created(el: HTMLElement, binding: DirectiveBinding, vnode: VNode) {
    if (vnode?.type === 'button') {
      el.addEventListener('click', elBlur(el));
    }
  },
  unmounted(el: HTMLElement) {
    el.removeEventListener('click', elBlur(el));
  },
};
